﻿<%@ Page Language="C#" MasterPageFile="~/Popup.Master" AutoEventWireup="true" CodeBehind="ReportHeader.aspx.cs"
    Inherits="PromotionEngine.ReportHeader" Title="Promotion Engine -  Promotion" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        var gird;
        function onChange(arg) {
            var selectedRows = this.select();
            var selectedDataItems = [];
            for (var i = 0; i < selectedRows.length; i++) {
                var dataItem = this.dataItem(selectedRows[i]);
                selectedDataItems.push(dataItem);
            }
            if (selectedDataItems.length > 0) {
                parent.LoadReport(selectedDataItems[0].ReportID, selectedDataItems[0].ReportCode, selectedDataItems[0].ReportName,
                                     selectedDataItems[0].ReportType, selectedDataItems[0].ReportURL, selectedDataItems[0].ReportQueryString);
            }
        }
        $(document).ready(function () {
            grid = $("#grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            type: "GET",
                            url: "ReportHeader.aspx/GetAllReports",
                            contentType: "application/json; charset=utf-8",
                          
                            dataType: "json"
                        },
                        destroy: {
                            type: "GET",
                            url: "ReportHeader.aspx/DeleteReport",
                            contentType: "application/json; charset=utf-8",
                           
                            dataType: "json"
                        },
                        parameterMap: function (data, operation) {
                            if (operation === "destroy") {
                                return { reportID: data.ReportID };
                            }
                        },
                       
                        serverPaging: true,
                        serverSorting: true,
                        serverFiltering: true
                    },
                    pageSize: 20,
                    type: "json",
                    schema: {
                        data: function (a) {
                            if (a.d != null) {
                                var data = a.d;
                                return JSON.parse(data);
                            }
                        },
                        total: function (response) {
                            return JSON.parse(response.d).length;
                        },
                        model: {
                            id: "ReportID",
                            fields: {
                                ReportID: { type: "string", validation: { required: true} },
                                ReportCode: { type: "string", validation: { required: true} },
                                ReportName: { type: "string", validation: { required: true} },
                                ReportType: { type: "string", validation: { required: true} },
                                ReferenceName: { type: "string", validation: { required: true} },
                                ReportURL: { type: "string", validation: { required: true} },
                                ReportQueryString: { type: "string", validation: { required: true} }
                            }
                        }
                    }
                },
                change: onChange,
                sortable: true,
                pageable: true,
                pageable: {
                    refresh: true
                },
                groupable: true,
                filterable: true,
                reorderable: true,
                resizable: true,
                selectable: "row",
                height: 480,
                toolbar: [{ name: 'excel'}],
                excel: {
                    fileName: "Report.xlsx",
                    filterable: true,
                    allPages: true
                },
                batch: true,
                columns: [{ field: "ReportID", title: "ID", width: 100 },
                            { field: "ReportCode", title: "Code", width: 200 },
                            { field: "ReportName", title: "Name" },
                            { field: "ReferenceName", title: "Report Type", width: 150 },
                            { field: "ReportURL", title: "Report URL", width: 300, hidden: true },
                            { field: "ReportQueryString", title: "Query String", width: 300, hidden: true },
                            { command: ["destroy"], title: "Action", width: "100px" }
                            ],
                editable: {
                    mode: "popup",
                    confirmation: "Are you sure you want to remove this report?"
                }
            }).data("kendoGrid");
        });
    </script>
    <div style="position: absolute; z-index: 0; margin-right: 8px;">
        <div id="grid">
        </div>
    </div>
</asp:Content>
